import java.util.ArrayDeque;
import java.util.Queue;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int q=sc.nextInt();
        int i;
        for(i=0;i<q;i++){
            int a=sc.nextInt();
            int b=sc.nextInt();
            int c=sc.nextInt();
            int count=0;
            int min=func(a,b,c);
            count+=min;
            b-=min;
            if(b>=2){
                count+=b-1;
            }
            System.out.println(count);
        }
    }
    public static int func(int a,int b,int c){
        int min=a;
        if(min>b){
            min=b;
        }
        if(min>c){
            min=c;
        }
        return min;
    }
}